package com.ruoyi.web.controller.control;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.control.domain.UseElectricityHistory;
import com.ruoyi.control.service.IUseElectricityHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智能用电历史Controller
 *
 * @author ruoyi
 * @date 2024-12-18
 */
@RestController
@RequestMapping("/useElectricityHistory/useElectricityHistory")
public class UseElectricityHistoryController extends BaseController
{
    @Autowired
    private IUseElectricityHistoryService useElectricityHistoryService;

    /**
     * 查询智能用电历史列表
     */
    @PreAuthorize("@ss.hasPermi('useElectricityHistory:useElectricityHistory:list')")
    @GetMapping("/list")
    public TableDataInfo list(UseElectricityHistory useElectricityHistory)
    {
        startPage();
        List<UseElectricityHistory> list = useElectricityHistoryService.selectUseElectricityHistoryList(useElectricityHistory);
        return getDataTable(list);
    }

    /**
     * 导出智能用电历史列表
     */
    @PreAuthorize("@ss.hasPermi('useElectricityHistory:useElectricityHistory:export')")
    @Log(title = "智能用电历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UseElectricityHistory useElectricityHistory)
    {
        List<UseElectricityHistory> list = useElectricityHistoryService.selectUseElectricityHistoryList(useElectricityHistory);
        ExcelUtil<UseElectricityHistory> util = new ExcelUtil<UseElectricityHistory>(UseElectricityHistory.class);
        util.exportExcel(response, list, "智能用电历史数据");
    }

    /**
     * 获取智能用电历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('useElectricityHistory:useElectricityHistory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(useElectricityHistoryService.selectUseElectricityHistoryById(id));
    }

    /**
     * 新增智能用电历史
     */
    @PreAuthorize("@ss.hasPermi('useElectricityHistory:useElectricityHistory:add')")
    @Log(title = "智能用电历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UseElectricityHistory useElectricityHistory)
    {
        return toAjax(useElectricityHistoryService.insertUseElectricityHistory(useElectricityHistory));
    }

    /**
     * 修改智能用电历史
     */
    @PreAuthorize("@ss.hasPermi('useElectricityHistory:useElectricityHistory:edit')")
    @Log(title = "智能用电历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UseElectricityHistory useElectricityHistory)
    {
        return toAjax(useElectricityHistoryService.updateUseElectricityHistory(useElectricityHistory));
    }

    /**
     * 删除智能用电历史
     */
    @PreAuthorize("@ss.hasPermi('useElectricityHistory:useElectricityHistory:remove')")
    @Log(title = "智能用电历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(useElectricityHistoryService.deleteUseElectricityHistoryByIds(ids));
    }
}
